package com.dou.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.dou.dao.UserMapper;
import com.dou.entity.User;
import com.dou.service.UserService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Service
@Component
public class UserServiceImpl implements UserService {
    @Autowired
    @SuppressWarnings("ALL")
    private UserMapper userMapper;
    @HystrixCommand(fallbackMethod = "back",
            commandProperties = {
                    //延迟操作
                    @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "2000"),
                    //报错超过10次数量进入back方法
                    @HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "10")
            }
    )
    @Override
    public List<User> getAllUser() {
        System.out.println("20883");
        if(false){
            throw new NullPointerException();
        }
        return userMapper.getAllUser();
    }
    public List<User> back(){
        System.out.println("这里是back方法");
        return new ArrayList<User>();
    }
}
